home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / jpi / players.bas < prev    next >
BASIC Source File  |  1998-01-29  |  12KB  |  292 lines

  1. Attribute VB_Name = "Players"
  2. Global Const FACTION_EDF = 1
  3. Global Const FACTION_ = 1
  4. Global Const PLAYERTYPE_COMPUTER = 1
  5. Global Const PLAYERTYPE_PERSON = 2
  6. Global Const PLAYERTYPE_GAMESCRIPT = 3
  7. Private Type PlayerData
  8.   PlayerIndex As Integer
  9.   NickName As String
  10. End Type
  11. Global LocalPlayer As PlayerData
  12.  
  13. Private Type BuildClass
  14.   Active As Boolean
  15.   Enabled As Boolean
  16.   ClassReference As Integer
  17. End Type
  18. Private Type BuildingType
  19.   Enabled As Boolean
  20.   CanBePlaced As Boolean
  21.   GoldRequired As Integer
  22.   GoldGathered As Integer
  23.   ClassReference As Integer
  24.   Active As Boolean
  25. End Type
  26. Private Type Side
  27.   Active As Boolean
  28.   Money As Long
  29.   NickName As String
  30.   PlayerType As Integer
  31.   BuildClasses(MaxObjModels) As BuildClass
  32.   BuildClassesActive As Integer
  33.   BuildsInProgress(MaxObjModels) As BuildingType
  34.   BuildsInProgressesActive As Integer
  35.   PrimaryBuildObjects(MAXBEHAVIORMODES) As Integer
  36.   BuildSpeeds(MAXBEHAVIORMODES) As Integer
  37.   TechLevel As Integer
  38.   Faction As Integer
  39.   CurrentlySelectedBuildClass As Integer
  40. End Type
  41. Global Const MAXPLAYERS = 10
  42. Global PlayerMax As Integer
  43. Global Player(MAXPLAYERS) As Side
  44. Global Const SIDE_SCENERY = -1 'For scenery
  45. Sub EvaluateBuildingAbility(PlayerIndex)
  46. Dim BuildableTypes(MaxObjModels) As Boolean
  47. For I = 1 To ObjectsActive
  48.   If Objects(I).Side = PlayerIndex Then
  49.     If CheckObject(I, OBJCHECK_ALIVE) = True Then
  50.       If ObjModels(Objects(I).ModelIndex).Abilities(ABILITY_BUILDS) = True Then
  51.         BuildableTypes(ObjModels(Objects(I).ModelIndex).Attributes(ATTRIBUTE_OBJECTBUILDTYPE)) = True
  52.       End If
  53.     End If
  54.   End If
  55. Next I
  56. For I = 1 To Player(PlayerIndex).BuildsInProgressesActive
  57.   If BuildableTypes(ObjModels(Player(PlayerIndex).BuildsInProgress(I).ClassReference).BehaviorType) = False Then
  58.     Call RemoveFromBuildStack(PlayerIndex, I)
  59.   End If
  60. Next I
  61. End Sub
  62. Sub KillAllPlayers()
  63. For I = 1 To PlayerMax
  64.   Call KillPlayer(I)
  65. Next I
  66. PlayerMax = 0
  67. End Sub
  68. Sub KillPlayer(PlayerIndex)
  69. Player(PlayerIndex).Active = False
  70. End Sub
  71. Function SpawnPlayer(Faction, Money, TechLevel)
  72. For I = 1 To MAXPLAYERS
  73.   If Player(I).Active = False Then
  74.     NewIndex = I
  75.     Exit For
  76.   End If
  77. Next I
  78. With Player(NewIndex)
  79.   .Active = True
  80.   .CurrentlySelectedBuildClass = 1
  81.   .Faction = Faction
  82.   .Money = Money
  83.   .TechLevel = TechLevel
  84. End With
  85. PlayerMax = PlayerMax + 1
  86. SpawnPlayer = NewIndex
  87. End Function
  88. Sub RecompilePrimaryBuildObjects(PlayerIndex)
  89. For I = 1 To MAXBEHAVIORMODES
  90.   If Player(PlayerIndex).PrimaryBuildObjects(I) = NOOBJECT Then
  91.     For I2 = 1 To ObjectsActive
  92.       If ObjModels(Objects(I2).ModelIndex).Abilities(ABILITY_BUILDS) = True Then
  93.         If ObjModels(Objects(I2).ModelIndex).Attributes(ATTRIBUTE_OBJECTBUILDTYPE) = I Then
  94.           If Objects(I2).Side = PlayerIndex Then
  95.             If CheckObject(I2, OBJCHECK_ALIVE) = True Then
  96.               Player(PlayerIndex).PrimaryBuildObjects(I) = I2
  97.               Exit For
  98.             End If
  99.           End If
  100.         End If
  101.       End If
  102.     Next I2
  103.   Else 'If it's already got an object
  104.     KeepIt = False
  105.     If CheckObject(Player(PlayerIndex).PrimaryBuildObjects(I), OBJCHECK_ALIVE) = True Then
  106.       If ObjModels(Objects(Player(PlayerIndex).PrimaryBuildObjects(I)).ModelIndex).Abilities(ABILITY_BUILDS) = True Then
  107.         If ObjModels(Objects(Player(PlayerIndex).PrimaryBuildObjects(I)).ModelIndex).Attributes(ATTRIBUTE_OBJECTBUILDTYPE) = I Then
  108.           KeepIt = True
  109.         End If
  110.       End If
  111.     End If
  112.     If KeepIt = False Then
  113.       Player(PlayerIndex).PrimaryBuildObjects(I) = NOOBJECT
  114.     End If
  115.   End If
  116. Next I
  117. End Sub
  118. Sub RecompileBuildEnables(PlayerIndex)
  119. For I = 1 To Player(PlayerIndex).BuildClassesActive
  120.   Player(PlayerIndex).BuildClasses(I).Enabled = True
  121.   For I2 = 1 To Player(PlayerIndex).BuildsInProgressesActive
  122.     If ObjModels(Player(PlayerIndex).BuildClasses(I).ClassReference).BehaviorType = ObjModels(Player(PlayerIndex).BuildsInProgress(I2).ClassReference).BehaviorType Then
  123.       Player(PlayerIndex).BuildClasses(I).Enabled = False
  124.     End If
  125.   Next I2
  126. Next I
  127. End Sub
  128. Sub RecompileBuildOptions(PlayerIndex)
  129. Player(PlayerIndex).BuildClassesActive = 0
  130. For I = 1 To ObjectsActive
  131.   If Objects(I).Side = PlayerIndex Then
  132.     If Objects(I).Active = True Then
  133.       If ObjModels(Objects(I).ModelIndex).Abilities(ABILITY_BUILDS) = True Then
  134.         For I2 = 1 To MaxObjModTypes
  135.           If Player(PlayerIndex).TechLevel >= ObjModels(I2).Attributes(ATTRIBUTE_TECHLEVEL) Then
  136.             If ObjModels(I2).BehaviorType = ObjModels(Objects(I).ModelIndex).Attributes(ATTRIBUTE_OBJECTBUILDTYPE) Then
  137.               If ObjModels(I2).Abilities(ABILITY_BUILDABLE) = True Then
  138.                 If ObjModels(I2).Attributes(ATTRIBUTE_SIDE) = Player(PlayerIndex).Faction Then
  139.                   BuildIt = True
  140.                   If ObjModels(I2).Attributes(ATTRIBUTE_REQUIREDBEFOREBUILD) <> NOOBJECT Then
  141.                     BuildIt = False
  142.                     For i3 = 1 To ObjectsActive
  143.                       If Objects(i3).Side = PlayerIndex Then
  144.                         If Objects(i3).Active = True Then
  145.                           If Objects(i3).ModelIndex = ObjModels(I2).Attributes(ATTRIBUTE_REQUIREDBEFOREBUILD) Then
  146.                             BuildIt = True
  147.                           End If
  148.                         End If
  149.                       End If
  150.                     Next i3
  151.                   End If
  152.                   For i3 = 1 To Player(PlayerIndex).BuildClassesActive
  153.                     If Player(PlayerIndex).BuildClasses(i3).ClassReference = I2 Then
  154.                       BuildIt = False
  155.                       Exit For
  156.                     End If
  157.                   Next i3
  158.                   If BuildIt = True Then
  159.                     Player(PlayerIndex).BuildClassesActive = Player(PlayerIndex).BuildClassesActive + 1
  160.                     Player(PlayerIndex).BuildClasses(Player(PlayerIndex).BuildClassesActive).Active = True
  161.                     Player(PlayerIndex).BuildClasses(Player(PlayerIndex).BuildClassesActive).ClassReference = I2
  162.                   End If
  163.                 End If
  164.               End If
  165.             End If
  166.           End If
  167.         Next I2
  168.       End If
  169.     End If
  170.   End If
  171. Next I
  172. Call RecompileBuildEnables(PlayerIndex)
  173.  
  174. If Player(PlayerIndex).CurrentlySelectedBuildClass > Player(PlayerIndex).BuildClassesActive Then Player(PlayerIndex).CurrentlySelectedBuildClass = Player(PlayerIndex).BuildClassesActive
  175. If Player(PlayerIndex).CurrentlySelectedBuildClass = 0 Then Player(PlayerIndex).CurrentlySelectedBuildClass = 1
  176. Call RecompileBuildSpeeds(PlayerIndex)
  177. If PlayerIndex = LocalPlayer.PlayerIndex Then
  178.   Call RedrawControlPanel
  179. End If
  180. End Sub
  181. Sub BuildObjectsChanged(PlayerIndex)
  182. Call RecompileBuildSpeeds(PlayerIndex)
  183. Call Players.RecompilePrimaryBuildObjects(PlayerIndex)
  184. Call Players.EvaluateBuildingAbility(PlayerIndex)
  185. Call Players.RecompileBuildOptions(PlayerIndex)
  186. Call Players.RecompileBuildSpeeds(PlayerIndex)
  187. If PlayerIndex = LocalPlayer.PlayerIndex Then
  188.   Call RedrawControlPanel
  189. End If
  190. End Sub
  191. Sub RecompileBuildSpeeds(PlayerIndex)
  192. For I = 1 To MAXBEHAVIORMODES
  193.   Player(PlayerIndex).BuildSpeeds(I) = 1
  194. Next I
  195. End Sub
  196. Function StartBuilding(PlayerIndex, ClassOptionsIndex) As Integer
  197. For I = 1 To Player(PlayerIndex).BuildsInProgressesActive
  198.   If ObjModels(Player(PlayerIndex).BuildsInProgress(I).ClassReference).BehaviorType = ObjModels(Player(PlayerIndex).BuildClasses(ClassOptionsIndex).ClassReference).BehaviorType Then
  199.     If Player(PlayerIndex).BuildsInProgress(I).Active = True Then
  200.       DoNotBuild = True
  201.     End If
  202.   End If
  203. Next I
  204. If DoNotBuild = False Then
  205.   Player(PlayerIndex).BuildsInProgressesActive = Player(PlayerIndex).BuildsInProgressesActive + 1
  206.   Player(PlayerIndex).BuildsInProgress(Player(PlayerIndex).BuildsInProgressesActive).Enabled = True
  207.   Player(PlayerIndex).BuildsInProgress(Player(PlayerIndex).BuildsInProgressesActive).Active = True
  208.   Player(PlayerIndex).BuildsInProgress(Player(PlayerIndex).BuildsInProgressesActive).GoldGathered = 0
  209.   Player(PlayerIndex).B